package com.example.demo.common;

import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.session.RowBounds;
import org.springframework.web.bind.annotation.RestController;

import java.util.Properties;

public class MyPageInterceptor implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object[] args = invocation.getArgs();
        MappedStatement ms = (MappedStatement) args[0]; // MappedStatement
        BoundSql boundSql = ms.getBoundSql(args[1]); // Object parameter
        String sql = boundSql.getSql();
        RowBounds rb = (RowBounds) args[2]; // RowBounds
        String limit = String.format("LIMIT %d,%d", rb.getOffset(), rb.getLimit());
        return null;
    }

    @Override
    public Object plugin(Object target) {
        return null;
    }

    @Override
    public void setProperties(Properties properties) {
        try {
            this.getClass().getMethod("").getAnnotation(RestController.class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
